/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

/**
 * @file
 * @brief ES8311 driver
 */

#ifndef __DSP_H__
#define __DSP_H__

#include "esp_types.h"
#include "esp_err.h"

#include "../dsp/es8311.h"

#ifdef __cplusplus
extern "C" {
#endif

struct dsp_driver_api {
    int (*init)(struct device* dev, const es8311_clock_config_t *const clk_cfg, const es8311_resolution_t res_in, const es8311_resolution_t res_out);
    int (*set_volume)(struct device* dev, int volume, int *volume_set);
    int (*get_volume)(struct device* dev, int *volume);
    void (*register_dump)(struct device* dev);
    int (*set_mute)(struct device* dev, bool enable);
    int (*set_mic_gain)(struct device* dev, es8311_mic_gain_t gain_db);
    int (*set_mic_config)(struct device* dev, bool digital_mic);
    int (*sample_frequency_config)(struct device* dev, int mclk_frequency, int sample_frequency);
    int (*output_fade)(struct device* dev, const es8311_fade_t fade);
    int (*input_fade)(struct device* dev, const es8311_fade_t fade);
};

static inline int dsp_dev_init(struct device* dev, const es8311_clock_config_t *const clk_cfg, const es8311_resolution_t res_in, const es8311_resolution_t res_out)
{
    const struct dsp_driver_api *api = dev->driver_api;

    return api->init(dev, clk_cfg, res_in, res_out);
}

static inline int dsp_dev_set_volume(struct device* dev, int volume, int *volume_set)
{
    const struct dsp_driver_api *api = dev->driver_api;

    return api->set_volume(dev, volume, volume_set);
}

static inline int dsp_dev_get_volume(struct device* dev, int *volume)
{
    const struct dsp_driver_api *api = dev->driver_api;

    return api->get_volume(dev, volume);
}

static inline void dsp_dev_register_dump(struct device* dev)
{
    const struct dsp_driver_api *api = dev->driver_api;

    api->register_dump(dev);
}

static inline int dsp_dev_set_mute(struct device* dev, bool enable)
{
    const struct dsp_driver_api *api = dev->driver_api;

    return api->set_mute(dev, enable);
}

static inline int dsp_dev_set_mic_gain(struct device* dev, es8311_mic_gain_t gain_db)
{
    const struct dsp_driver_api *api = dev->driver_api;

    return api->set_mic_gain(dev, gain_db);
}

static inline int dsp_dev_set_mic_config(struct device* dev, bool digital_mic)
{
    const struct dsp_driver_api *api = dev->driver_api;

    return api->set_mic_config(dev, digital_mic);
}

static inline int dsp_dev_sample_frequency_config(struct device* dev, int mclk_frequency, int sample_frequency)
{
    const struct dsp_driver_api *api = dev->driver_api;

    return api->sample_frequency_config(dev, mclk_frequency, sample_frequency);
}

static inline int dsp_dev_output_fade(struct device* dev, const es8311_fade_t fade)
{
    const struct dsp_driver_api *api = dev->driver_api;

    return api->output_fade(dev, fade);
}

static inline int dsp_dev_input_fade(struct device* dev, const es8311_fade_t fade)
{
    const struct dsp_driver_api *api = dev->driver_api;

    return api->input_fade(dev, fade);
}

#ifdef __cplusplus
}
#endif

#endif // __DSP_H__